//
//  SuccessView.m
//  Azkar
//
//  Created by 王易 on 2018/8/29.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "SuccessView.h"
#import "UIView+CustomAutoLayout.h"


/**
 成功View
 */
@implementation SuccessView

- (instancetype)init
{
    if (self == [super init]) {
        
        [self initUI];
        
    }
    return self;
    
}
- (void)initUI
{
    self.backgroundColor = [UIColor clearColor];
    
    self.frame = [UIScreen mainScreen].bounds;
    
    MyRelativeLayout *rootLayout = [MyRelativeLayout new];
    rootLayout.myBottom = 0;
    rootLayout.myTop = 0;
    rootLayout.myHorzMargin= 0;
    rootLayout.backgroundColor = [UIColor clearColor];
    [self addSubview:rootLayout];
    
    MyRelativeLayout *alerLayout = [MyRelativeLayout new];
    alerLayout.myHorzMargin = alerLayout.myTop = 0;
    alerLayout.myHeight = 70 + [PhoneUtil statusBarHeight];
    alerLayout.backgroundColor = RGBA(0,115,47,0.94);;
    [rootLayout addSubview:alerLayout];
    
    UILabel *successTitle = [UILabel new];
    successTitle.centerYPos.equalTo(alerLayout.centerYPos).offset([PhoneUtil statusBarHeight] * 0.5);
    successTitle.centerXPos.equalTo(alerLayout.centerXPos).offset(12);
    successTitle.wrapContentSize = YES;
    successTitle.textColor = Color(@"#FFFFFF");
    successTitle.font = FontSize(16);
    successTitle.text = TLString(@"greeting_cards_release_successful");
    [rootLayout addSubview:successTitle];
    
    UIImageView *imageV = [UIImageView new];
    imageV.myWidth = imageV.myHeight = 16;
    imageV.image = Image(@"successful_ic");
    imageV.centerYPos.equalTo(successTitle.centerYPos);
    imageV.trailingPos.equalTo(successTitle.leadingPos).offset(13);
    [rootLayout addSubview:imageV];
}
- (void)showView
{

    WeakSelf
    [[SKPopupHelper shareInstance] skpop_showView:self defaultHideEnable:YES animate:YES duration:0.3f willAnimate:^(UIWindow *window, UIView *view) {
        window.backgroundColor = [UIColor clearColor];
        
        [view alignParentCenter:CGPointMake(0.0, 0.0)];
        [view alignParentBottomWithMargin:view.height];
    } animating:^(UIWindow *window, UIView *view) {
        window.backgroundColor = [UIColor colorWithWhite:0.0 alpha: 0];
        
        [view alignParentTop];
    } completion:^(UIWindow *window, UIView *view) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
           StrongSelf
            WeakSelf
            [[SKPopupHelper shareInstance] skpop_hideView:self animate:YES duration:0.3f willAnimate:^(UIWindow *window, UIView *view) {
           
            } animating:^(UIWindow *window, UIView *view) {
                [view alignParentCenter:CGPointMake(0.0, 0.0)];
                [view alignParentTopWithMargin:-view.height];
            } completion:^(UIWindow *window, UIView *view) {
                StrongSelf
                if (self.SuccessBlock) {
                    self.SuccessBlock();
                }
            }];
      
        });
    }];
}
@end
